package com.hogwarts.webui.pageobj;

import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;

public class JsOps {
    public static void inputData(WebDriver driver, String from, String to, String trainDate){
//        JsPage.getFrom(driver).clear();
        JsPage.getFrom(driver).click();
        JsPage.getFrom(driver).sendKeys(from);

//        JsPage.getFrom(driver).clear();
        JsPage.getFrom(driver).click();
        JsPage.getTo(driver).sendKeys(to);

        JsPage.getTrainDate(driver).sendKeys(trainDate);
    }

    public static void inputDataJS(WebDriver driver, String from, String to, String trainDate){
        execJS(driver, JsPage.getFrom(driver), from);
        execJS(driver, JsPage.getTo(driver), to);
        execJS(driver, JsPage.getTrainDate(driver), trainDate);
    }

    private static void execJS(WebDriver driver, WebElement elem, String value){
        JavascriptExecutor js = (JavascriptExecutor) driver;
        js.executeScript("arguments[0].value='" + value + "'", elem);
    }
}
